//============================================================================
// Copyright (C) 2010 Brett R. Jones
// All Rights Reserved
//
// You may redistribute and/or modify for non commercial and commercial uses
// provided this copyright notice remains in place and is not modified
//
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// brettjones1900@gmail.com
// http://www.p2panarchy.com
//============================================================================

// implements basic sound play functionality callable from jni

package com.roguetreasure.destroytheworld;

// implements game interface to native code
public class GameInterface
{
	// declare native functions

    private static native void nativeGamePause();
    private static native void nativeGameResume();
    private static native void nativeGameRestart();
    private static native void nativeGameShutdown();

    private static native void nativeAppSleep();
    private static native void nativeAppResume();
	//=== vars ===// 
	private static final String LOG_TAG = "GameInterface: ";
	private static DestroyWorldActivity m_oActivity;
	
	
    //=== constructors ===//  
    public GameInterface() 
    {
    	//Log.i(LOG_TAG, "constructed");
    }
    
    //=== startup ===//  
    public void Startup(DestroyWorldActivity oActivity) 
    {
    	//Log.i(LOG_TAG, "startup");
        m_oActivity = oActivity;
    }
    
    //------------------------------------------------------------------------
    // to native code
    //------------------------------------------------------------------------
    //------------------------------------------------------------------------
    //! tell native code to pause game
	public void GamePause() 
    {
		nativeGamePause();
    }
	
    //------------------------------------------------------------------------
    //! tell native code to resume game
	public void GameResume() 
    {
		nativeGameResume();
    }
	
    //------------------------------------------------------------------------
    //! tell native code application has went to sleep
	public void AppPause() 
    {
		nativeAppSleep();
    }
	
    //------------------------------------------------------------------------
    //! tell native code application has been awakened
	public void AppResume() 
    {
		nativeAppResume();
    }
	
    //------------------------------------------------------------------------
    //! tell native code to start a new game
	public void GameRestart() 
    {
		nativeGameRestart();
    }
	
	//! called when app is about to exit
	public void GameShutdown()
	{
		nativeGameShutdown();
	}
    
    //------------------------------------------------------------------------
    // from native code
    //------------------------------------------------------------------------
	//! pause the game 
	//@SuppressWarnings("static-access")
	public static void GameIsPaused() 
    {
    }
	
	//! resume game
	public static void GameIsResumed() 
    {
    }

	//! vibrate phone
    public void Vibrate(long s64MilliSec )
    {
	    if(m_oActivity.m_oVibrator != null)
	    {
	    	m_oActivity.m_oVibrator.vibrate(s64MilliSec);   
	    	  
	    	// 2. Vibrate in a Pattern with 500ms on, 500ms off for 5 times   
	    	//long[] pattern = { 500, 300 };   
	    	//vibrator.vibrate(pattern, 5);  
	    	//vibrator.vibrate(pattern, -1);
	    }
    }

};
